<?php
/**
 * Created by PhpStorm.
 * User: itboye
 * Date: 2017/1/14
 * Time: 13:47
 */
namespace Admin\Controller;

use Admin\Api\ImgManageApi;
use Admin\Api\MemberApi;
class ImgManageController extends AdminController{
    public function index(){
        $map = [];
        $page = array('curpage' => I('get.p'), 'size' => 20);
        $order = " create_time desc ";
        $result = apiCall(ImgManageApi::QUERY, array($map,$page,$order));
        if($result){
            $this->assign('list',$result['info']['list']);
            $this->assign('show',$result['info']['show']);
            $this->display();
        }else{
            $this->error($result['info']);
        }
    }

    public function add(){
        if(IS_GET){
            $map = [];
            $page = array('curpage' => I('get.p'), 'size' => C('LIST_ROW'));
            $order = " update_time desc ";
            $result = apiCall(ImgManageApi::QUERY, array($map, $page, $order));
            if ($result['status']) {
                $this -> assign("show", $result['info']['show']);
                $this -> assign("list", $result['info']['list']);
                $this -> display();
            } else {
                $this -> error($result['info']);
            }
        }else{
            $entity = array(
                'main_img'       =>I('post.main_img',''),
                'post_type'      =>'post_type',
            );
            $result = apiCall("Admin/Post/add", array($entity));
            if(!$result['status']){
                $this->error($result['info']);
            }

            $this->success("操作成功！",U('Admin/Post/index'));
        }
    }
    //详情展示
    public function detail(){
        $id = I('id');
        $uname = I('username');
        if(empty($id)){
            $this->error('参数错误！');
        }
        $map = ['id'=>$id];
        $result = apiCall(ImgManageApi::QUERYNOPAGING,array($map));
        $imgs = $result['info'][0]['img_url_list'];
        if($result){
            $this->assign('result',$result['info']);
            $this->assign('id',$id);
            $this->assign('username',$uname);
            $this->assign('imgs',explode(",",$imgs));
            $this->display();
        }else{
            $this->error($result['info']);
        }
    }
    //请求删除
    public function del(){
        $id    = I('id');
        if(empty($id)){
            $this->error('参数错误！');
        }
        $map = ['id'=>$id];
        $result = apiCall(ImgManageApi::DELETE,array($map));
        if($result['status']){
            $this->success(L('RESULT_SUCCESS'),U('ImgManage/index'));
        }else{
            $this->error('操作失败!');
        }
    }
    //请求批量删除
    public function bulkDelete(){
        $ids    = I('ids');
        if(empty($ids)){
            $this->error('参数错误!');
        }
        $map = ['id'=>['in',$ids]];
        $result = apiCall(ImgManageApi::DELETE,array($map));
        if($result['status']){
            $this -> success(L('RESULT_SUCCESS'));
        }else{
            LogRecord('[INFO]' . $result['info'], '[FILE] ' . __FILE__ . ' [LINE] ' . __LINE__);
            $this->error($result['info']);
        }

    }

}